<?php
class Xanhte_BlockShowHide extends XCube_ActionFilter
{
	function postFilter()
	{
		$this->mRoot->mDelegateManager->add('Legacy_RenderSystem.SetupXoopsTpl',
											array($this, 'appendHeader'));

	}
	
	function appendHeader(&$xoopsTpl)
	{
		$this->includeJs('lib/prototype.js', $xoopsTpl);
		$this->includeJs('lib/cookiemanager.js', $xoopsTpl);
		$this->includeJs('xoopsblock.js', $xoopsTpl);
	}
	
	
	function includeJs($js, &$xoopsTpl)
	{
		static $included_js;
		!isset($included_js) and $included_js = array();
		if (isset($included_js[$js])){
			 return;
		}
		$included_js[$js] = true;
		
		$xmh = $xoopsTpl->get_template_vars('xoops_module_header');
		if (preg_match('{\.js$}', $js)){
			$xmh = sprintf('%s<script src="%s/modules/xanhte/js/%s" type="text/javascript"></script>'."\n",
						   $xmh, XOOPS_URL, $js);
		} else {
			$xmh = sprintf('%s<script>%s</script>'."\n",
						   $xmh, $js);
		}
		
		$xoopsTpl->assign('xoops_module_header', $xmh);
		return;
	}

}